using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.WizardFramework;
using VSSDKAssist.Assets.Converters;
using System.Globalization;
using VSSDKAssist.Recipes.Common.CustomPages;
using VSSDKAssist.Recipes.Common.Helpers;

namespace VSSDKAssist.Recipes.CreateToolOptionsPage
{
	/// <summary>
	/// Custom page for CreateToolOptionsPageCP2 recipe
	/// </summary>
	public partial class CreateToolOptionsPageCP2 : WizardPageBase
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="CreateToolOptionsPageCP2"/> class.
		/// </summary>
		public CreateToolOptionsPageCP2()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CreateToolOptionsPageCP2"/> class.
		/// </summary>
		/// <param name="wizard">The <see cref="T:Microsoft.Practices.WizardFramework.WizardForm"/>that will host the new page.</param>
		public CreateToolOptionsPageCP2(WizardForm wizard)
			: base(wizard)
		{
			InitializeComponent();
			SetControls();
		}

		/// <summary>
		/// Gets or sets the name of the category.
		/// </summary>
		/// <value>The name of the category.</value>
		[RecipeArgument]
		public string CategoryName
		{
			get { return (string)veCategoryName.Value; }
			set
			{
				if(value != null)
				{
					veCategoryName.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the category caption.
		/// </summary>
		/// <value>The category caption.</value>
		[RecipeArgument]
		public string CategoryCaption
		{
			get { return (string)veCategoryCaption.Value; }
			set
			{
				if(value != null)
				{
					veCategoryCaption.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the name of the page.
		/// </summary>
		/// <value>The name of the page.</value>
		[RecipeArgument]
		public string PageName
		{
			get { return (string)vePageName.Value; }
			set
			{
				if(value != null)
				{
					vePageName.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the page caption.
		/// </summary>
		/// <value>The page caption.</value>
		[RecipeArgument]
		public string PageCaption
		{
			get { return (string)vePageCaption.Value; }
			set
			{
				if(value != null)
				{
					vePageCaption.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether [supports export dialog].
		/// </summary>
		/// <value>
		/// 	<c>true</c> if [supports export dialog]; otherwise, <c>false</c>.
		/// </value>
		[RecipeArgument]
		public bool SupportsExportDialog
		{
			get { return chkSupportsExportDialog.Checked; }
			set
			{
				chkSupportsExportDialog.Checked = value;
			}
		}

		/// <summary>
		/// Gets or sets the export dialog description.
		/// </summary>
		/// <value>The export dialog description.</value>
		[RecipeArgument]
		public string ExportDialogDescription
		{
			get { return (string)veExportDescription.Value; }
			set
			{
				if(value != null)
				{
					veExportDescription.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// 	<see cref="P:Microsoft.WizardFramework.WizardPage.IsDataValid"/>
		/// Search for all the arguments that this Wizard gather
		/// If all of them are not null, then the Wizard can finish
		/// </summary>
		/// <value></value>
		public override bool IsDataValid
		{
			get
			{
				errorProvider.SetError(veExportDescription, string.Empty);

				if(chkSupportsExportDialog.Checked)
				{
					if(DictionaryService.GetValue("ExportDialogDescription") == null)
					{
						errorProvider.SetError(veExportDescription, Properties.Resources.InvalidValue);
						return false;
					}
				}

				return base.IsDataValid;
			}
		}

		/// <summary>
		/// Gets or sets the site of the control.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.ComponentModel.ISite"></see> associated with the <see cref="T:System.Windows.Forms.Control"></see>, if any.</returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public override ISite Site
		{
			get
			{
				return base.Site;
			}
			set
			{
				base.Site = value;
				if(value != null)
				{
					this.veCategoryName.BeginInit();
					this.veCategoryName.ValueType = typeof(string);
					base.Site.Container.Add(veCategoryName);
					this.veCategoryName.EndInit();

					this.veCategoryCaption.BeginInit();
					this.veCategoryCaption.ValueType = typeof(string);
					base.Site.Container.Add(veCategoryCaption);
					this.veCategoryCaption.EndInit();

					this.vePageName.BeginInit();
					this.vePageName.ValueType = typeof(string);
					base.Site.Container.Add(vePageName);
					this.vePageName.EndInit();

					this.vePageCaption.BeginInit();
					this.vePageCaption.ValueType = typeof(string);
					base.Site.Container.Add(vePageCaption);
					this.vePageCaption.EndInit();

					this.veExportDescription.BeginInit();
					this.veExportDescription.ValueType = typeof(string);
					base.Site.Container.Add(veExportDescription);
					this.veExportDescription.EndInit();
				}
			}
		}

		private void veCategoryName_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string categoryName = (string)veCategoryName.Value;
			DictionaryService.SetValue("CategoryName", categoryName);
		}

		private void veCategoryCaption_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string categoryCaption = (string)veCategoryCaption.Value;
			DictionaryService.SetValue("CategoryCaption", categoryCaption);
		}

		private void vePageName_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string pageName = (string)vePageName.Value;
			DictionaryService.SetValue("PageName", pageName);
		}

		private void vePageCaption_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string pageCaption = (string)vePageCaption.Value;
			DictionaryService.SetValue("PageCaption", pageCaption);
		}

		private void veExportDescription_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string exportDescription = (string)veExportDescription.Value;
			DictionaryService.SetValue("ExportDialogDescription", exportDescription);
		}

		private void chkSupportsExportDialog_CheckedChanged(object sender, EventArgs e)
		{
			lblExportDescription.Visible = chkSupportsExportDialog.Checked;
			veExportDescription.Visible = chkSupportsExportDialog.Checked;
			pctExportDescription.Visible = chkSupportsExportDialog.Checked;
			DictionaryService.SetValue("SupportsExportDialog", chkSupportsExportDialog.Checked);
		}

		private void SetControls()
		{
			lblExportDescription.Visible = true;
			veExportDescription.Visible = true;
			pctExportDescription.Visible = true;
		}

		private void pctPageCaption_Click(object sender, EventArgs e)
		{
			Bitmap bitmap = CustomPageHelper.GetBitmapResource("PageCaption");

			if(bitmap != null)
			{
				InfoForm infoForm = new InfoForm(bitmap);

				infoForm.ShowDialog();
			}
		}

		private void pctCategoryCaption_Click(object sender, EventArgs e)
		{
			Bitmap bitmap = CustomPageHelper.GetBitmapResource("CategoryCaption");

			if(bitmap != null)
			{
				InfoForm infoForm = new InfoForm(bitmap);

				infoForm.ShowDialog();
			}
		}

		private void pctExportDescription_Click(object sender, EventArgs e)
		{
			Bitmap bitmap = CustomPageHelper.GetBitmapResource("ExportDescription");

			if(bitmap != null)
			{
				InfoForm infoForm = new InfoForm(bitmap);

				infoForm.ShowDialog();
			}
		}
	}
}